package com.atguigu.eduservice.controller;


import com.atguigu.comMonutils.R;
import com.atguigu.eduservice.entity.execl.oneLevelSubject;
import com.atguigu.eduservice.service.EduSubjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;

/**
 * <p>
 * 课程科目 前端控制器
 * </p>
 *
 * @author testjava
 * @since 2024-04-06
 */
@RestController
@RequestMapping("/eduservice/subject")
@CrossOrigin
public class EduSubjectController {
    @Autowired
    private EduSubjectService eduSubjectService;


    //获得上传过来的文件
    @PostMapping("addSubject")
    public R addSubject(MultipartFile file) throws IOException {
        eduSubjectService.saveSubject(file, eduSubjectService);
        return R.ok().message("添加课程分类数据成功");
    }

    /**
     * 这是一个获得全部课程的数据.

     * @return
     */
    @GetMapping("getAllSubject")
    public R getAllSubject() {
        List allSubject = eduSubjectService.getAllSubject();
        return R.ok().data("allSubject", allSubject);
    }

}

